package data;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class PackagePrice extends AbstractData {
	private long id = -1;
	private  long hotelId;
	private String roomtypeString;
	private RoomType roomtype;
	private double priceperNight;
	private double Extrabed;
	private double UpchargePerson;
	public PackagePrice(){
		
	}
	
	public PackagePrice(long id){
		this.id=id;
		
	}
	public void setId(long id) {
		this.id = id;
	}
	
	public long getId() {
		return id;
	}
	
	public long getHotelId() {
		return hotelId;
	}
	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}
	
	public RoomType getRoomtype() {
		if (roomtype == null && !(roomtypeString == null || roomtypeString.isEmpty())) {
			RoomType c = new RoomType(Long.parseLong(roomtypeString));	
			c.LoadData();
			roomtype = c;
		}
		return roomtype;
	}
	
	public void setRoomtype(RoomType roomtype) {
		this.roomtypeString = String.format("%d", roomtype.getId());
		this.roomtype = roomtype;
	}
	
	public String getRoomTypeString() {
		return roomtypeString;
	}
	
	public void setRoomTypeString(String roomtypeString) {
		this.roomtypeString = roomtypeString;
	}
	
	public double getPriceperNight() {
		return priceperNight;
	}
	
	public void setPriceperNight(double priceperNight) {
		this.priceperNight = priceperNight;
	}
	
	public double getExtrabed() {
		return Extrabed;
	}
	
	public void setExtrabed(double extrabed) {
		Extrabed = extrabed;
	}
	
	public double getUpchargePerson() {
		return UpchargePerson;
	}
	
	public void setUpchargePerson(double upchargePerson) {
		UpchargePerson = upchargePerson;
	}
	
	
	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.PackagePrice);
		else
			item = new Entity(this.key);

		item.setProperty("hotelId", this.hotelId);
		item.setProperty("roomTypeId", this.roomtypeString);
		item.setProperty("priceperNight", this.priceperNight);
		item.setProperty("Extrabed", this.Extrabed);
		item.setProperty("UpchargePerson", this.UpchargePerson);
		return item;
	}
	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.hotelId = (Long) entity.getProperty("hotelId");
		this.roomtypeString = String.valueOf(entity.getProperty("roomTypeId"));
		this.priceperNight = (Double) entity.getProperty("priceperNight");
		this.Extrabed = (Double) entity.getProperty("Extrabed");
		this.UpchargePerson = (Double) entity.getProperty("UpchargePerson");
		this.key = entity.getKey();
	}
	
	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.PackagePrice, this.id);
			setEntity(entity);
		}
	}
}
